package com.monlyu.action.devices;

import java.util.HashMap;

import com.monlyu.action.PageAction;
import com.monlyu.bean.Pages;
import com.monlyu.bo.DevicesBo;
import com.monlyu.vo.DeviceSupply;
import com.monlyu.vo.Devices;

/**
 * @author SongJun
 * @since 2010-2-22
 * @description 设备信息管理
 */

public class EditDevicesAction extends PageAction {
	private Devices devices;
	private DevicesBo devicesBo;
	private Pages<DeviceSupply> ds;
	private Long supid;
	private HashMap devicesSupplys;

	private String supidInfo;

	public String getSupidInfo() {
		return supidInfo;
	}

	public void setSupidInfo(String supidInfo) {
		this.supidInfo = supidInfo;
	}

	public Long getSupid() {
		return supid;
	}

	public void setSupid(Long supid) {
		this.supid = supid;
	}

	public Pages<DeviceSupply> getDs() {
		return ds;
	}

	public void setDs(Pages<DeviceSupply> ds) {
		this.ds = ds;
	}

	public Devices getDevices() {
		return devices;
	}

	public void setDevices(Devices devices) {
		this.devices = devices;
	}

	public void setDevicesBo(DevicesBo devicesBo) {
		this.devicesBo = devicesBo;
	}

	@Override
	public String execute() throws Exception {
		if (devices != null
				&& ((null == devices.getId() && !devicesBo.isInclude(devices)) || null != devices
						.getId())) {
			devicesBo.insertOrUpdate(devices, supid);
			//ds = devicesBo.getDeviceSupplys(getDefPage());
			devicesSupplys = devicesBo.getDeviceSupplys();
			return ajax("yes;操作成功!");
		} else {
			return ajax("no;设备编号已经存在了，请重新输入！！！");
		}
	}

	public String toEdit() {
		if (devices != null && devices.getId() != null) {
			devices = devicesBo.getDevicesById(devices.getId());
		}
//		if (devices.getDevicesupply() != null) {
//			supid = devices.getDevicesupply().getId();
//			supidInfo = devices.getDevicesupply().getUnitName() + "(" + supid
//					+ ")";
//		}
		//ds = devicesBo.getDeviceSupplys(getDefPage());
		devicesSupplys = devicesBo.getDeviceSupplys();
		return view("editDevices.jsp");
	}

	public String toAdd() {
		//ds = devicesBo.getDeviceSupplys(getDefPage());
		devicesSupplys = devicesBo.getDeviceSupplys();
		return view("editDevices.jsp");
	}

	public HashMap getDevicesSupplys() {
		return devicesSupplys;
	}

	public void setDevicesSupplys(HashMap devicesSupplys) {
		this.devicesSupplys = devicesSupplys;
	}
}
